<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="utf-8">
    <title>送货地址</title>
    <meta name="keywords" content=""/>
    <meta name="description" content=""/>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <link rel="stylesheet" href="../../layui/css/layui.css">
    <link rel="stylesheet" href="../../xznstatic/css/common.css"/>
    <link rel="stylesheet" href="../../xznstatic/css/style.css"/>
    <script type="text/javascript" src="../../xznstatic/js/jquery-1.11.3.min.js"></script>
    <script type="text/javascript" src="../../xznstatic/js/jquery.SuperSlide.2.1.1.js"></script>
    <link rel="stylesheet" href="../../xznstatic/css/bootstrap.min.css" />

    <link rel="stylesheet" href="../../css/theme.css"/>
</head>
<style>
    html::after {
        position: fixed;
        top: 0;
        right: 0;
        left: 0;
        bottom: 0;
        content: '';
        display: block;
        background-attachment: fixed;
        background-size: cover;
        background-position: center;
    }

    /*轮播图相关 start*/
    #swiper {
        overflow: hidden;
    }

    #swiper .layui-carousel-ind li {
        width: 20px;
        height: 10px;
        border-width: 0;
        border-style: solid;
        border-color: rgba(0, 0, 0, .3);
        border-radius: 6px;
        background-color: #f7f7f7;
        box-shadow: 0 0 6px rgba(255, 0, 0, .8);
    }

    #swiper .layui-carousel-ind li.layui-this {
        width: 30px;
        height: 10px;
        border-width: 0;
        border-style: solid;
        border-color: rgba(0, 0, 0, .3);
        border-radius: 6px;
    }
    /*轮播图相关 end*/

    /*列表*/
    .recommend {
        padding: 10px 0;
        display: flex;
        justify-content: center;
        background-repeat: no-repeat;
        background-position: center center;
        background-size: cover;
    }

    .recommend .box {
        width: 1002px;
        margin: 0 auto;
    }

    .recommend .box .title {
        padding: 10px 5px;
        display: flex;
        justify-content: space-between;
        align-items: center;
        box-sizing: border-box;
    }

    .recommend .box .title span {
        padding: 0 10px;
        font-size: 16px;
        line-height: 1.4;
    }

    .recommend .box .filter {
        padding: 0 10px;
        display: flex;
        align-items: center;
        box-sizing: border-box;
        width: 100%;
        flex-wrap: wrap;
    }

    .recommend .box .filter .item-list {
        display: flex;
        align-items: center;
    }

    .recommend .box .filter .item-list .lable {
        font-size: 14px;
        color: #333;
        box-sizing: border-box;
    }

    .recommend .box .filter .item-list input {
        padding: 0 10px;
        box-sizing: border-box;
        outline: none;
    }

    .recommend .box .filter button {
        display: flex;
        padding: 0 10px;
        box-sizing: border-box;
        align-items: center;
        justify-content: center;
        outline: none;
    }

    .recommend .box .filter button i {
        margin-right: 4px;
    }

    .recommend .box .list {
        display: flex;
        flex-wrap: wrap;
    }

    .recommend .box .list .list-item {
        flex: 0 0 25%;
        padding: 0 5px;
        box-sizing: border-box;
    }

    .recommend .box .list .list-item .list-item-body {
        cursor: pointer;
        border: 1px solid rgba(0, 0, 0, 3);
        padding: 5px;
        box-sizing: border-box;
    }

    .recommend .box .list .list-item-body img {
        width: 100%;
        height: 100px;
        display: block;
        margin: 0 auto;
    }

    .recommend .box .list .list-item-body .info {
        display: flex;
        flex-wrap: wrap;
    }

    .recommend .box .list .list-item-body .info .price {
        padding-top: 5px;
        color: red;
        font-size: 14px;
        text-align: center;
        box-sizing: border-box;
    }

    .recommend .box .list .list-item-body .info .name {
        padding-top: 5px;
        color: red;
        font-size: 14px;
        text-align: center;
        box-sizing: border-box;
    }

    .recommend .box .list .list-item3 {
        flex: 0 0 33.33%;
    }

    .recommend .box .list .list-item5 {
        flex: 0 0 25%;
    }

    .recommend .box .news {
        display: flex;
        flex-wrap: wrap;
        padding: 0;
        width: 100%;
    }

    .recommend .box .news .list-item {
        flex: 0 0 50%;
        padding: 0 10px;
        box-sizing: border-box;
    }

    .recommend .box .news .list-item .list-item-body {
        cursor: pointer;
        border: 1px solid rgba(0, 0, 0, 3);
        padding: 10px;
        box-sizing: border-box;
        display: flex;
    }

    .recommend .box .news .list-item .list-item-body img {
        width: 120px;
        height: 100%;
        display: block;
        margin: 0 auto;
    }

    .recommend .box .news .list-item .list-item-body .item-info {
        flex: 1;
        display: flex;
        justify-content: space-between;
        flex-direction: column;
        padding-left: 10px;
        box-sizing: border-box;
    }

    .recommend .box .news .list-item .list-item-body .item-info .name {
        padding-top: 5px;
        color: red;
        font-size: 14px;
        box-sizing: border-box;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-line-clamp: 1;
        -webkit-box-orient: vertical;
    }

    .recommend .box .news .list-item .list-item-body .item-info .time {
        padding-top: 5px;
        color: red;
        font-size: 14px;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-line-clamp: 1;
        -webkit-box-orient: vertical;
        box-sizing: border-box;
    }

    .recommend .box .news .list-item1 {
        flex: 0 0 100%;
    }

    .recommend .box .news .list-item3 {
        flex: 0 0 33.33%;
    }

    .index-pv1 .animation-box:hover {
        transform: perspective(1000px) translate3d(0px, 0px, 0px) scale(1.1) rotate(0deg) skew(0deg, 0deg);
        transition: all 1.1s;
    }


    .layui-laypage .layui-laypage-count {
        padding: 0 10px;
    }

    .layui-laypage .layui-laypage-skip {
        padding-left: 10px;
    }
    /*标题*/
    .index-title {
        text-align: center;
        box-sizing: border-box;
        width: 980px;
        display: flex;
        justify-content: center;
        align-items: center;
        flex-direction: column;
    }
    .index-title span {
        padding: 0 10px;
        line-height: 1.4;
    }
    .btn-container {
        margin-top: 20px;
        text-align: right;
        margin-bottom: 60px;
        border: 2px dotted #EEEEEE;
        padding: 20px;
    }
    .center-container {
        width: 980px;
        margin: 0 auto;
        margin-top: 20px;
        text-align: center;
        display: flex;
        margin-bottom: 20px;
    }

    .center-container .left-container {
        border: 2px dotted #EEEEEE;
        background: #FFFFFF;
        width: 200px;
        padding-top: 20px;
        height: 600px;
    }

    .center-container .right-container {
        flex: 1;
        border: 2px dotted #EEEEEE;
        background: #FFFFFF;
        text-align: left;
        padding: 20px;
        padding-top: 40px;
    }

    .center-container .layui-nav-tree {
        width: 100%;
    }
    .center-container .layui-nav {
        position: inherit;
    }
    .center-container .layui-nav-tree .layui-nav-item {
        height: 44px;
        line-height: 44px;
        font-size: 16px;
        color: rgba(17, 17, 17, 1);
        border-width: 0px 0px 1px 0px;
        border-style: solid;
        border-radius: 0;
        background-color: #fff;
        text-align: center;
    }
    .center-container .layui-nav-tree .layui-nav-item.layui-this {
        font-size: 16px;
        color: rgba(17, 17, 17, 1);
        border-width: 0;
        border-style: solid;
        border-radius: 0;
    }
    .center-container .layui-nav-tree .layui-nav-item:hover {
        font-size: 14px;
        color: #fff;
        border-width: 0;
        border-style: solid;
        border-radius: 0;
    }
    .center-container .layui-nav-tree .layui-nav-item a {
        line-height: inherit;
        height: auto;
        background-color: inherit;
        color: inherit;
        text-decoration: none;
    }
    /*表格 end*/
</style>
<body>
<div id="app">
    <div class="banner">
        <div class="layui-carousel" id="swiper"
             :style='{"boxShadow":"0 0 0px rgba(255,0,0,.8)","margin":"0 auto","borderColor":"rgba(0,0,0,.3)","borderRadius":"0px","borderWidth":"0","width":"100%","borderStyle":"solid"}'>
            <div carousel-item>
                <div v-for="(item,index) in swiperList" :key="index">
                    <img style="width: 100%;height: 100%;object-fit:cover;" :src="item.img"/>
                </div>
            </div>
        </div>
    </div>
    <!-- 新增修改模态框 -->
    <el-dialog :title="addresTitle" :visible.sync="dialogFormVisible" :modal-append-to-body="false">
        <el-form :model="addressFrom" :rules="rules" ref="ruleForm">
            <el-form-item label="收货人" :label-width="formLabelWidth" prop="addressName">
                <el-input v-model="addressFrom.addressName" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="电话" :label-width="formLabelWidth" prop="addressPhone">
                <el-input v-model="addressFrom.addressPhone" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="地址" :label-width="formLabelWidth" prop="addressDizhi">
                <el-input v-model="addressFrom.addressDizhi" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="是否默认地址" :label-width="formLabelWidth" prop="isdefaultTypes">
                <el-switch v-model="addressFrom.isdefaultTypes"></el-switch>
            </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button @click="dialogFormVisible = false">取 消</el-button>
            <el-button type="primary" @click="saveaddress()">确 定</el-button>
        </div>
    </el-dialog>

    <!-- 标题 -->
     <div class="index-title sub_backgroundColor" :style='{"padding":"10px","boxShadow":"0 0 2px rgba(160, 67, 26, 1)","margin":"10px auto","borderColor":"rgba(0,0,0,.3)","color":"rgba(255, 255, 255, 1)","borderRadius":"4px","borderWidth":"0","fontSize":"20px","borderStyle":"solid","height":"auto"}'>
         <span>USER / ADDRESS</span><span>收货地址</span>
     </div>

    <!-- 标题 -->

    <div class="center-container">
        <!-- 个人中心菜单 config.js-->
<div class="left-container" :style='{"padding":"0","boxShadow":"0px 0px 1px rgba(181, 181, 181, 1)","margin":"0","borderColor":"rgba(191, 191, 191, 1)","backgroundColor":"rgba(255, 255, 255, 1)","borderRadius":"0","borderWidth":"0 0 1px 0","width":"160px","borderStyle":"solid"}'>
    <ul class="layui-nav layui-nav-tree">
        <li v-for="(item,index) in centerMenu" v-bind:key="index" class="layui-nav-item" :class="item.url=='../address/list.html'?'layui-this':''">
            <a :href="'javascript:jump(\''+item.url+'\')'">{{item.name}}</a>
        </li>
    </ul>
</div>
        <!-- 个人中心菜单 -->
        <div class="right-container sub_borderColor" style="padding-top: 0;" :style='{"padding":"5px","margin":"0px","borderColor":"rgba(99, 83, 83, 1)","backgroundColor":"#fff","borderRadius":"0","borderWidth":"0","borderStyle":"solid"}'>
            <div class="btn-container" :style='{"padding":"0 10px","boxShadow":"0 0 0px rgba(255,0,0,.8)","margin":"10px 0 10px 0","borderColor":"rgba(0,0,0,.3)","backgroundColor":"rgba(255, 255, 255, 1)","borderRadius":"4px","alignItems":"flex-end","borderWidth":"0","borderStyle":"solid","justifyContent":"flex-end","height":"64px"}'>
                <button @click="addaddress" class="layui-btn layui-btn-lg btn-theme sub_backgroundColor" :style='{"padding":"0 15px","boxShadow":"0 0 8px rgba(0,0,0,0)","margin":"0 0 0 10px","borderColor":"#409EFF","color":"#fff","borderRadius":"4px","borderWidth":"0","width":"auto","fontSize":"14px","borderStyle":"solid","height":"40px"}'>
                    <i v-if="true" class="layui-icon">&#xe654;</i> 添加新地址
                </button>
            </div>
            <table class="layui-table" lay-skin="nob">
                <thead>
                <tr>
                    <th>主键 </th>
                    <th>收货人 </th>
                    <th>电话 </th>
                    <th>地址 </th>
                    <th>是否默认地址 </th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                <tr v-for="(item,index) in dataList" v-bind:key="index">

                    <th style="width: auto">{{item.id}}</th>
                    <th style="width: auto">{{item.addressName}}</th>
                    <th style="width: auto">{{item.addressPhone}}</th>
                    <th>{{item.addressDizhi}}</th>
                    <th style="width: auto">{{item.isdefaultValue}}</th>
                    <td style="width: auto">
                        <button @click="updateeaddress(item)" type="button"
                                class="layui-btn layui-btn-radius layui-btn-sm layui-btn-warm">
                            <i class="layui-icon">&#xe642;</i> 修改
                        </button>
                        <button @click="deleteClick(item.id)" type="button"
                                class="layui-btn layui-btn-radius layui-btn-sm btn-theme">
                            <i class="layui-icon">&#xe640;</i> 删除
                        </button>
                    </td>
                </tr>
                </tbody>
            </table>
            <div class="pager" id="pager"></div>
        </div>
    </div></div>

<script src="../../xznstatic/js/bootstrap.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../../layui/layui.js"></script>
<script src="../../js/vue.js"></script>
<!-- 引入element组件库 -->
<script src="../../xznstatic/js/element.min.js"></script>
<!-- 引入element样式 -->
<link rel="stylesheet" href="../../xznstatic/css/element.min.css">
<script src="../../js/config.js"></script>
<script src="../../modules/config.js"></script>
<script src="../../js/utils.js"></script>

<script type="text/javascript">
    var vue = new Vue({
        el: '#app',
        data: {
            swiperList: [],
            isdefaultTypesList: [],

            //查询条件
            searchForm: {
                page: 1
                ,limit: 8
            },


            //地址相关
            centerMenu: centerMenu,
            addresTitle: null,
            dialogFormVisible: false,
            formLabelWidth: '120px',
            addressFrom: {
                id: "",
                addressName: "",
                addressPhone: "",
                addressDizhi: "",
                isdefaultTypes: false,
            },
            rules: {
                addressName: [
                    { required: true, message: '收货人 不能为空', trigger: 'blur' },
                ],
                 addressPhone: [
                     {  required: true, message: '电话不能为空', trigger: 'blur' },
                     {  pattern: /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/,
                         message: '电话格式不对',
                         trigger: 'blur'
                     }
                 ],
                addressDizhi: [
                    { required: true, message: '地址 不能为空', trigger: 'blur' },
                ],
                isdefaultTypes: [
                    { required: true, message: '是否默认地址 不能为空', trigger: 'blur' },
                ],
             },

            dataList: [],
        },
        filters: {
            subString: function(val) {
                if (val) {
                    val = val.replace(/<[^<>]+>/g, '').replace(/undefined/g, '');
                    if (val.length > 60) {
                        val = val.substring(0, 60);
                        val+='...';
                    }
                    return val;
                }
                return '';
            }
        },
        computed: {
        },
        methods: {
            isAuth(tablename, button) {
                return isFrontAuth(tablename, button);
            }
            ,jump(url) {
                jump(url);
            }
            ,jumpCheck(url,check1,check2) {
                if(check1 == "2" || check1 == 2){//级联表的逻辑删除字段[1:未删除 2:已删除]
                    layui.layer.msg("已经被删除", {
                        time: 2000,
                        icon: 2
                    });
                    return false;
                }
                if(check2 == "2"  || check2 == 2){//是否下架[1:上架 2:下架]
                    layui.layer.msg("已经下架", {
                        time: 2000,
                        icon: 2
                    });
                    return false;
                }
                this.jump(url);
            }
			,deleteClick(id) {
				layui.layer.confirm('是否确认删除？', {
					btn: ['删除', '取消'] //按钮
				}, function() {
					layui.http.requestJson(`address/delete`, 'post', [id], function(res) {
						layer.msg('删除成功', {
							time: 2000,
							icon: 6
						}, function(res) {
							window.location.reload();
						});
					})
				});
			}
			,updateeaddress(res) {
				this.addressFrom = null
				this.addresTitle = '修改地址'
				this.dialogFormVisible = true
				if(res.isdefaultTypes == 2){
					res.isdefaultTypes = true
				}else{
					res.isdefaultTypes = false
				}
                this.addressFrom = res
			}
			,addaddress() {
                this.addressFrom={
					id: "",
					addressName: "",
					addressPhone: "",
					addressDizhi: "",
					isdefaultTypes: false,
                },
                this.addresTitle = '新增地址'
                this.dialogFormVisible = true
			}
			,saveaddress(){
                let _this = this
                if(this.addressFrom.isdefaultTypes){
                    this.addressFrom.isdefaultTypes = 2
                }else{
                    this.addressFrom.isdefaultTypes = 1
                }

                this.$refs["ruleForm"].validate(valid => {
                    if (valid) {
                        layui.http.requestJson(`address/${!this.addressFrom.id ? "save" : "update"}`, 'post', this.addressFrom, function (res) {
                            layer.msg('操作成功', {
                                time: 2000,
                                icon: 6
                            }, function () {
                                _this.dialogFormVisible = false
                                window.location.reload();
                            });
                            _this.dialogFormVisible = false
                        });
                    }
                });
            }        }
    });

    layui.use(['layer', 'element', 'carousel', 'laypage', 'http', 'jquery', 'laydate', 'tinymce'], function() {
        var layer = layui.layer;
        var element = layui.element;
        var carousel = layui.carousel;
        var laypage = layui.laypage;
        var http = layui.http;
        var laydate = layui.laydate;
        var tinymce = layui.tinymce;
        window.jQuery = window.$ = jquery = layui.jquery;

        // var id = http.getParam('id');

        // 获取轮播图 数据
        http.request('config/list', 'get', {
            page: 1,
            limit: 5
        }, function (res) {
            if (res.data.list.length > 0) {
                let swiperList = [];
                res.data.list.forEach(element => {
                    if(element.value != null){
                        swiperList.push({
                            img: element.value
                        });
                    }
                });
                vue.swiperList = swiperList;

                vue.$nextTick(() => {
                    carousel.render({
                        elem: '#swiper',
                        width: '100%',
                        height: '450px',
                        arrow: 'hover',
                        anim: 'default',
                        autoplay: 'true',
                        interval: '3000',
                        indicator: 'inside'
                    });
                });
            }
        });


           //当前表的 是否默认地址 字段 字典表查询方法
           function isdefaultTypesSelect() {
               http.request("dictionary/page?page=1&limit=100&sort=&order=&dicCode=isdefault_types", 'get', {}, function (res) {
                   if(res.code == 0){
                       vue.isdefaultTypesList = res.data.list;
                   }
               });
           }

		// 获取列表数据
		http.request('address/page', 'get', {
			page: 1,
			limit: 5,
			yonghu: localStorage.getItem('userid')
		}, function(res) {
			vue.dataList = res.data.list
			// 分页
			laypage.render({
				elem: 'pager',
				count: res.data.total,
				limit: 5,
				jump: function(obj, first) {
					//首次不执行
					if (!first) {
						http.request('address/list', 'get', {
							page: obj.curr,
							limit: obj.limit,
							yonghu: localStorage.getItem('userid')
						}, function(res) {
							vue.dataList = res.data.list
						})
					}
				}
			});
		})    });

    window.xznSlide = function () {
        jQuery(".banner").slide({mainCell: ".bd ul", autoPlay: true, interTime: 5000});
        jQuery("#ifocus").slide({
            titCell: "#ifocus_btn li",
            mainCell: "#ifocus_piclist ul",
            effect: "leftLoop",
            delayTime: 200,
            autoPlay: true,
            triggerTime: 0
        });
        jQuery("#ifocus").slide({titCell: "#ifocus_btn li", mainCell: "#ifocus_tx ul", delayTime: 0, autoPlay: true});
        jQuery(".product_list").slide({
            mainCell: ".bd ul",
            autoPage: true,
            effect: "leftLoop",
            autoPlay: true,
            vis: 5,
            trigger: "click",
            interTime: 4000
        });
    };
</script>
</body>
</html>
